package com.library.servlet.user;

import com.library.dao.BorrowRecordDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/returnBook")
public class ReturnBookServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int recordId = Integer.parseInt(request.getParameter("recordId"));
        int bookId = Integer.parseInt(request.getParameter("bookId"));

        BorrowRecordDAO recordDAO = new BorrowRecordDAO();
        boolean success = recordDAO.returnBook(recordId, bookId);

        if (success) {
            request.setAttribute("message", "归还成功");
        } else {
            request.setAttribute("error", "归还失败");
        }
        request.getRequestDispatcher("/user/borrowRecords").forward(request, response);
    }
}    